// Package svc
// @Author zhongxc
// @Date 2024/7/30 11:11:00
// @Desc
package svc

import (
	"go.uber.org/zap"
	"vben-admin/pkg/hook"
	"vben-api/config"
	"vben-common/utils"
)

type UserInfo struct {
	UserId   int64
	UserName string
}

type ServiceContext struct {
	Config   *config.Config
	ZapLog   *zap.Logger // 日志指针
	userInfo *UserInfo
}

func NewServiceContext(cnf *config.Config) *ServiceContext {
	return &ServiceContext{
		Config: cnf,
		ZapLog: utils.CreateZapFactory(hook.ZapLogHandler, cnf.ZapLogConfig),
	}
}

func (s *ServiceContext) SetUserInfo(userId int64, userName string) {
	userInfo := &UserInfo{
		UserId:   userId,
		UserName: userName,
	}
	s.userInfo = userInfo
}

func (s *ServiceContext) GetUserInfo() *UserInfo {
	return s.userInfo
}

func (s *ServiceContext) ResetUserInfo() {
	s.userInfo = &UserInfo{}
}
